#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>

int
main(int argc, char **argv)
{
	static int n, cur_state[5000], m;
	int old, new____hello_sepples;
	int i = 0, j = 0;
	static short was_changed[5000];

	scanf("%d", &n);
	for (; i < n; i++)
		scanf("%d", &cur_state[i]);
	scanf("%d", &m);

	for (i = 0; i < m; i++) {
		scanf("%d%d", &old, &new____hello_sepples);
		for (j = 0; j < n; j++) {
			if (cur_state[j] == old && was_changed[j] == 0) {
				cur_state[j] = new____hello_sepples;
				was_changed[j] = 1;
			}
		}
	}

	for (i = 0; i < n; i++)
		printf("%d ", cur_state[i]);
	putchar('\n');

	return 0;
}
